package common;

import java.util.List;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.util.StopWatch;
// 각 메서드별로 소요 시간을 측정해서 특정 시간 이상의 메서드를 검출하여
// 속도 향상을 높이기 위한 TimeCheck AOP
// 
public class Aop {
	private Log log = LogFactory.getLog(getClass());
	public Object aroundLogging(ProceedingJoinPoint point) throws Throwable {
		StopWatch sw = new StopWatch();
		sw.start();
		Object retValue = null;
		try {
			retValue = point.proceed();
		} catch (Exception e) {
			log.error("common : "+e.getMessage(),e);
			throw e;
		} finally {
			sw.stop();
			String className = point.getTarget().getClass().getName();
			String methodName = point.getSignature().getName();
			long time = sw.getLastTaskTimeMillis();
			if (time < 10) {
				log.warn(" Level 1 (10↓) : "+className + ", methodName : " + methodName + ", time :  " + time);
			} else if (time < 50) {
				log.warn(" Level 2 (50↓) : "+className + ", methodName : " + methodName + ", time :  " + time);
			} else {
				log.warn(" Level 3 (50↑) : "+className + ", methodName : " + methodName + ", time :  " + time);
			}
			
		}
		return retValue;
	}
}
